package com.ruoyi.web.controller.invoice.dingding;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.CorpInfo;
import com.ruoyi.system.service.ICorpInfoService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "钉钉开票单位接口")
@RestController
@AllArgsConstructor
@RequestMapping("invoice/corp")
public class DingCorpInfoController {
    @Autowired
    private ICorpInfoService corpInfoService;

    @RequestMapping(value = "/getCorpInfo", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult queryCorpInfo(@RequestParam String corpId) {
        CorpInfo corpInfo = corpInfoService.selectCorpInfoById(corpId);
        return AjaxResult.success(corpInfo);
    }


    @RequestMapping(value = "/updateCorpInfo", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult updateCorpInfo(@RequestBody CorpInfo infoDto) {
        CorpInfo corpInfo = corpInfoService.selectCorpInfoById(infoDto.getCorpId());
        if (corpInfo == null) {
            return AjaxResult.error("不存在该企业");
        }
        corpInfo.setCorpName(infoDto.getCorpName());
        corpInfo.setCorpAddress(infoDto.getCorpAddress());
        corpInfo.setAccount(infoDto.getAccount());
        corpInfo.setTel(infoDto.getTel());
        corpInfo.setNssbh(infoDto.getNssbh());
        corpInfo.setIssuingBank(infoDto.getIssuingBank());
        corpInfoService.updateCorpInfo(corpInfo);
        return AjaxResult.success(corpInfo);
    }
}
